<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="单位名称" prop="roleName">
        <el-input v-model="queryParams.input" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="税号" prop="roleName">
        <el-input v-model="queryParams.input" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="保证金状态" prop="roleName">
        <el-select v-model="queryParams.roleName" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button size="mini" @click="handleAdd">新增</el-button>
        <el-button size="mini" @click="refund">退款</el-button>
        <el-button size="mini" @click="examine">审核</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="单位名称" prop="roleKey" />
      <el-table-column label="税号" prop="roleKey" />
      <el-table-column label="法人代表" prop="roleKey" />
      <el-table-column label="注册地址" prop="roleKey" />
      <el-table-column label="邮箱" prop="roleKey" />
      <el-table-column label="开票地址" prop="roleKey" />
      <el-table-column label="保证金" prop="roleKey" />
      <el-table-column label="保证金状态" prop="roleKey" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增对话框 -->
    <el-dialog title="新增" :visible.sync="open" width="500px" append-to-body>
      <el-form :model="form" label-width="80px">
        <el-form-item label="往来客户" :rules="[{ required: true, message: '请选择'}]">
          <el-select v-model="form.value" style="width: 100%;" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="保证金" :rules="[{ required: true, message: '请输入'}]">
          <el-input 
            v-model="form.roleName" 
            placeholder="请输入" 
            oninput="value=value.replace(/^([0-9-]\d*\.?\d{0,2})?.*$/,'$1')"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="open=false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 新增对话框 -->
    <el-dialog title="退款" :visible.sync="openRefund" width="500px" append-to-body>
      <el-form :model="formRefund" label-width="80px">
        <el-form-item label="退款原因" :rules="[{ required: true, message: '请输入'}]">
          <el-input v-model="formRefund.roleName" placeholder="请输入" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRefund">确 定</el-button>
        <el-button @click="openRefund=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  data() {
    return {
      // 表格多选框
      ids: [],
      // 下拉数据
      options: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 新增表单字段
      open: false,
      form: {},
      // 退款字段
      openRefund: false,
      formRefund: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表格多选事件
    handleSelectionChange() {

    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    // 新增
    handleAdd() {
      this.reset();
      this.open = true
    },
    // 表单确定
    submit() {

    },
    // 退款
    refund() {
      this.formRefund = {}
      this.openRefund = true
    },
    // 退款确定
    submitRefund() {

    },
    // 审核
    examine() {
      this.$emit('change', 'Examine')
    }
  }
};
</script>
